package com.algo;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.client.config.NacosConfigService;

import java.util.Properties;
import java.util.concurrent.Executor;

public class SimpleNacosClient {

    public static void main(String[] args) {
        try {
            Properties properties = new Properties();
            properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
            properties.put(PropertyKeyConst.NAMESPACE, "dev");

            NacosConfigService configService = new NacosConfigService(properties);

            String content = configService.getConfig("best-practise", "YCC-TEST-GROUP", 5000);

            System.out.println("first get config : " + content);

            configService.addListener("best-practise", "YCC-TEST-GROUP", new Listener() {
                @Override
                public Executor getExecutor() {
                    return null;
                }

                @Override
                public void receiveConfigInfo(String configInfo) {
                    System.out.println("update config : " + configInfo);
                }
            });

            System.in.read();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
